import axios from "axios";
import type { Method, AxiosRequestConfig } from "axios";

const serivce = axios.create({
  baseURL: "http://121.40.105.156:8088/api/mallApi/",
  timeout: 10000,
  withCredentials: true,
});

serivce.interceptors.response.use((response: any) => response.data);
type Date<T> = {
  code: number;
  msg: string;
  data: T;
};

const request = <T>(url: string, method: Method, submitData: object) => {
  return serivce.request<T, Date<T>>({
    url,
    method,
    [method.toLocaleLowerCase() === "get" ? "params" : "data"]: submitData,
  });
};

export default request;
